package com.adams.right.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.adams.access.db.bean.Right;
import com.adams.encache.mechanism.CacheUtil;
import com.adams.right.dao.RightDao;
import com.adams.right.service.RightService;
import com.adams.utils.Page;

/**
 * 
 * 
 * File Name : RightServiceImpl.java
 * 
 * @Description : 权限管理服务类，提供对权限的增、删、改查功能
 * @author 902990封文进
 */
@Service("rightService")
@Transactional
public class RightServiceImpl implements RightService
{

	@Autowired
	private RightDao rightDao;

	public void setRightDao(RightDao rightDao)
	{
		this.rightDao = rightDao;
	}

	/**
	 * 
	 * Description : 创建权限
	 * 
	 * @param right
	 * 
	 */
	@Transactional(rollbackFor = java.lang.Exception.class)
	public void createRight(Right right)
	{
		right.setVersion(1);
		rightDao.save(right);
		CacheUtil.clearCacheByClass(Right.class);
	}

	/**
	 * 
	 * Description : 更新权限
	 * 
	 * @param right
	 * 
	 */
	@Transactional(rollbackFor = java.lang.Exception.class)
	public void updateRight(Right right)
	{
		rightDao.update(right);
		CacheUtil.clearCacheByClass(Right.class);
	}

	/**
	 * 
	 * Description : 删除权限
	 * 
	 * @param right
	 * 
	 */
	@Transactional(rollbackFor = java.lang.Exception.class)
	public void deleteRight(Right right)
	{
		rightDao.delete(right);
		CacheUtil.clearCacheByClass(Right.class);
	}

	/**
	 * 
	 * Description : 根据编号查询权限
	 * 
	 * @param id
	 * @return Right
	 * 
	 */
	@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
	public Right queryById(Long id)
	{
		return rightDao.get(id);
	}

	/**
	 * 
	 * Description : 根据权限码查询权限
	 * 
	 * @param code
	 * @return Right
	 * 
	 */
	@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
	public Right queryByCode(String code)
	{
		return rightDao.queryByCode(code);
	}

	/**
	 * 
	 * Description : 根据分页查询权限
	 * 
	 * @param page
	 * @return Page<Right>
	 * 
	 */
	@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
	public Page<Right> queryAllByPage(Page<Right> page)
	{
		return rightDao.queryAllByPage(page);
	}

}
